import 'package:base_lib/dictionary/entity/medical_single_dose_entity.dart'
    as SingleDoseBean;
import 'package:base_lib/dictionary/entity/medical_treat_frequency_entity.dart'
    as TreatBean;
import 'package:base_lib/dictionary/entity/medical_treat_route_entity.dart'
    as TreatRouteBean;

/// code : 0
/// data : {"totalRow":51,"pageIndex":1,"totalPage":2,"datas":[{"goodsID":"20090114481560931131107001","medicineID":"20090114475617942041103001","productBrand":"","sickness":"","productFactory":"浙江震元","medicineName":"制霉素片【基】50万u*100片","orgID":"19101610315474350800511001","thirdGoodsID":"000030","medicineForm":"抗感染用药","price":40.25,"otcType":1,"productSpec":"","medicineFormID":0},{"goodsID":"20090114481565826211107001","medicineID":"20090114475816823821103001","productBrand":"","sickness":"","productFactory":"石药集团中诺","medicineName":"阿莫西林胶囊【基】0.25g*10粒*5板/盒","orgID":"19101610315474350800511001","thirdGoodsID":"000057","medicineForm":"抗感染用药","price":37.4,"otcType":1,"productSpec":"","medicineFormID":0}]}

class MedicalSearchEntity {
  int _code;
  Data _data;

  int get code => _code;

  Data get data => _data;

  MedicalSearchEntity({int code, Data data}) {
    _code = code;
    _data = data;
  }

  MedicalSearchEntity.fromJson(dynamic json) {
    _code = json["code"];
    _data = json["data"] != null ? Data.fromJson(json["data"]) : null;
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map["code"] = _code;
    if (_data != null) {
      map["data"] = _data.toJson();
    }
    return map;
  }
}

/// totalRow : 51
/// pageIndex : 1
/// totalPage : 2
/// datas : [{"goodsID":"20090114481560931131107001","medicineID":"20090114475617942041103001","productBrand":"","sickness":"","productFactory":"浙江震元","medicineName":"制霉素片【基】50万u*100片","orgID":"19101610315474350800511001","thirdGoodsID":"000030","medicineForm":"抗感染用药","price":40.25,"otcType":1,"productSpec":"","medicineFormID":0},{"goodsID":"20090114481565826211107001","medicineID":"20090114475816823821103001","productBrand":"","sickness":"","productFactory":"石药集团中诺","medicineName":"阿莫西林胶囊【基】0.25g*10粒*5板/盒","orgID":"19101610315474350800511001","thirdGoodsID":"000057","medicineForm":"抗感染用药","price":37.4,"otcType":1,"productSpec":"","medicineFormID":0}]

class Data {
  int _totalRow;
  int _pageIndex;
  int _totalPage;
  List<Datas> _datas;

  int get totalRow => _totalRow;

  int get pageIndex => _pageIndex;

  int get totalPage => _totalPage;

  List<Datas> get datas => _datas;

  Data({int totalRow, int pageIndex, int totalPage, List<Datas> datas}) {
    _totalRow = totalRow;
    _pageIndex = pageIndex;
    _totalPage = totalPage;
    _datas = datas;
  }

  Data.fromJson(dynamic json) {
    _totalRow = json["totalRow"];
    _pageIndex = json["pageIndex"];
    _totalPage = json["totalPage"];
    if (json["datas"] != null) {
      _datas = [];
      json["datas"].forEach((v) {
        _datas.add(Datas.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map["totalRow"] = _totalRow;
    map["pageIndex"] = _pageIndex;
    map["totalPage"] = _totalPage;
    if (_datas != null) {
      map["datas"] = _datas.map((v) => v.toJson()).toList();
    }
    return map;
  }
}

/// goodsID : "20090114481560931131107001"
/// medicineID : "20090114475617942041103001"
/// productBrand : ""
/// sickness : ""
/// productFactory : "浙江震元"
/// medicineName : "制霉素片【基】50万u*100片"
/// orgID : "19101610315474350800511001"
/// thirdGoodsID : "000030"
/// medicineForm : "抗感染用药"
/// price : 40.25
/// otcType : 1
/// productSpec : ""
/// medicineFormID : 0

class Datas {
  String goodsID;
  String medicineID;
  String productBrand;
  String sickness;
  String productFactory;
  String medicineName;
  String orgID;
  String thirdGoodsID;
  String medicineForm;
  double price = 0.0; // 此药品的总价
  int otcType;
  String productSpec;
  int medicineFormID;

  //从 medicine_info_entity 里面拿的数据
  String productUnit;

  String formType;

  String dosage;

  //从 medicine_info_entity 里面拿的数据 END

  //线下订单后台需要参数

  int medicineClassID = 0;

  String medicineClassName = '西药';

  String specification = '';

  // 用量
  int medicineAmount;

  //用量
  String usage;

  // 单位
  String unit;

  double unitPrice;

  // 服用剂量
  int takeDose;

  // 服用频次
  String takeFrequence;

  // 服用方法
  String takeDirection;

  // 用药天数
  int medicationDays;

  // 备注
  String memo = '';

  //疗程
  String course = '';

  //线下订单后台需要参数 end

  ///自定义添加 start
  //单次用药单位
  SingleDoseBean.Data singleUnit;

  //给药频率
  TreatBean.Data treat;

  //给药途径
  TreatRouteBean.Data treatRoute;

  ///自定义添加  end

  Datas(
      {String goodsID,
      String medicineID,
      String productBrand,
      String sickness,
      String productFactory,
      String medicineName,
      String orgID,
      String thirdGoodsID,
      String medicineForm,
      double price,
      int otcType,
      String productSpec,
      int medicineFormID}) {
    goodsID = goodsID;
    medicineID = medicineID;
    productBrand = productBrand;
    sickness = sickness;
    productFactory = productFactory;
    medicineName = medicineName;
    orgID = orgID;
    thirdGoodsID = thirdGoodsID;
    medicineForm = medicineForm;
    unitPrice = price;
    otcType = otcType;
    productSpec = productSpec;
    medicineFormID = medicineFormID;
  }

  Datas.fromJson(dynamic json) {
    goodsID = json["goodsID"];
    medicineID = json["medicineID"];
    productBrand = json["productBrand"];
    sickness = json["sickness"];
    productFactory = json["productFactory"];
    medicineName = json["medicineName"];
    orgID = json["orgID"];
    thirdGoodsID = json["thirdGoodsID"];
    medicineForm = json["medicineForm"];
    unitPrice = json["price"];
    otcType = json["otcType"];
    productSpec = json["productSpec"];
    medicineFormID = json["medicineFormID"];
  }

  Map<String, dynamic> toJson() {
    if (medicineClassName.contains('中药')) {
      return <String, dynamic>{
        'price': price,
        'medicineID': medicineID,
        'goodsID': goodsID,
        'medicineClassID': medicineClassID,
        'medicineClassName': medicineClassName,
        'productFactory': productFactory,
        'medicineName': medicineName,
        'specification': specification,
        'medicineAmount': medicineAmount,
        'usage': usage,
        'unit': unit,
        'unitPrice': unitPrice,
        'formType': formType,
        'takeDose': takeDose ?? '',
        'takeFrequence': takeFrequence ?? '',
        'takeDirection': takeDirection,
        'memo': memo,
        'course': course,
        'medicationDays': medicationDays ?? '',
        'otcType': otcType,
        'thirdGoodsID': thirdGoodsID,
      };
    } else
      return <String, dynamic>{
        'price': price,
        'medicineID': medicineID,
        'goodsID': goodsID,
        'medicineClassID': medicineClassID,
        'medicineClassName': medicineClassName,
        'productFactory': productFactory,
        'medicineName': medicineName,
        'specification': specification,
        'medicineAmount': medicineAmount,
        'unit': unit,
        'unitPrice': unitPrice,
        'formType': formType,
        'takeDose': takeDose,
        'takeFrequence': takeFrequence,
        'takeDirection': takeDirection,
        'memo': memo,
        'medicationDays': medicationDays,
        'otcType': otcType,
        'thirdGoodsID': thirdGoodsID,
      };
  }
}
